package com.snok.emenu;

import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.widget.LinearLayout;

public class snok_emenu_main extends Activity {
	protected int 	   						mMenuCount=5;
	protected MenuView 						mMenuView;
	protected MenuButton 					mButtons[];
	protected LeftLayoutClickListener 		mMenuButtonClickListener;
	protected LeftLayoutFocusChangeListener mMenuButtonFocusChangeListener;
	//public static Bitmap					mBitmap;
	
	public class LeftLayoutClickListener implements View.OnClickListener
	{
		public void onClick(View v)
		{
			MenuButton b = (MenuButton)v;
			SetCurrentMenuCategory(b.ID);
		}
	}
	
	public class LeftLayoutFocusChangeListener implements View.OnFocusChangeListener
	{
		public void onFocusChange(View v, boolean hasFocus)
		{
			//MenuButton b = (MenuButton)v;
			if(hasFocus == true)
			{
				System.out.println("dd");
			}
			else
			{
				System.out.println("dd");
			}
		}
	}
	
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) 
    {
    	int 			i;
    	LinearLayout 	llo;
    	LinearLayout 	llo_left;
    	LinearLayout.LayoutParams lp;
    	LinearLayout.LayoutParams lp_button;

        super.onCreate(savedInstanceState);
        
        this.requestWindowFeature(Window.FEATURE_NO_TITLE);
        this.setContentView(R.layout.snok_emenu_main);
        
        mMenuView = new MenuView(this);
        
    	lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT,
    			LinearLayout.LayoutParams.FILL_PARENT);
        
        llo = (LinearLayout) this.findViewById(R.id.snok_emenu_right_menu);
    
        llo.addView(mMenuView,lp);
        
        //mMenuView.setOnTouchListener(l);
        
        
        llo_left = (LinearLayout) this.findViewById(R.id.snok_emenu_left_menu);

        lp_button = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT,60);
        
        mMenuButtonClickListener = new LeftLayoutClickListener();
        
        mMenuButtonFocusChangeListener = new LeftLayoutFocusChangeListener();
        
        mButtons = new MenuButton[mMenuCount];
        
        for( i = 0 ; i < mMenuCount ; i++)
        {
        	mButtons[i] = new MenuButton(this,i);
        	mButtons[i].setOnClickListener(mMenuButtonClickListener);
        	mButtons[i].setOnFocusChangeListener(mMenuButtonFocusChangeListener);
        	llo_left.addView(mButtons[i],lp_button);
        }
        
        //mBitmap = getBitmapFromSd(null);
    }
    
	public Bitmap getBitmapFromSd(String  imgFilePath) {
		//Bitmap bmp = BitmapFactory.decodeResource(this.getResources(),R.drawable.tex);
		BitmapFactory.Options opt = new BitmapFactory.Options();
		opt.inScaled = false;
		Bitmap bmp = BitmapFactory.decodeFile("/storage/sdcard0/tex.jpg",opt);
		return bmp;
	}
    
    public void SetCurrentMenuCategory(int MenuID)
    {
    	int i;
    	for( i = 0 ; i < mMenuCount ; i++)
    	{
    		mButtons[i].SetState(mButtons[i].ID == MenuID);
    	}
    }
}